Skip to main content

Procedure

Create Stored Procedure

This interface allows you to create and manage stored procedures using AI assistance. You can define the procedure name, parameters, return type, and generate the procedure code automatically.

Interface Overview

The Create Procedure screen consists of the following elements:

  • Name:
    • A text input field where you can enter the name of the stored procedure.
    • Example: getUserData.

Code Editor

The center of the screen features a code editor where you can manually write or edit the stored procedure. This editor allows you to define the logic of your procedure in SQL or any other supported query language.

  • Code Editor Features:
    • Syntax highlighting for SQL.
    • A dark theme for better focus.
    • Example: Define the procedure body here.

AI-Generated Procedure Code

The Generate Stored Procedure Code with AI section allows you to generate the stored procedure code automatically based on the information provided.

  • Message Field:

    • You can add a message or description in this field to guide the AI in generating the stored procedure.
    • Example: "Generate a stored procedure to fetch user details based on user_id."
  • Send Button:

    • Click this button to send your request to the AI, which will generate the appropriate stored procedure code.

Actions Available

  • Send: Generates the procedure code automatically based on the message provided.

Params and Return Type

To the right of the editor, there are two buttons:

  • Params:
    • Use this button to add parameters for the stored procedure (e.g., input/output parameters).
  • Return Type:
    • Define the return type of the stored procedure.

Defining Parameters

The Params section allows you to define the input parameters for your stored procedure. These parameters help pass values to the stored procedure when it's executed.

Parameters Interface

  • Name:

    • This field allows you to specify the name of the parameter. In the example provided, the parameter is named parameter 1.
  • Type:

    • The type of the parameter. This could be a string, int, float, etc., depending on the type of data being passed into the procedure.
    • In this example, the type is string.
  • Value (Optional):

    • You can assign a default value to the parameter if necessary.
  • Add/Delete Parameter:

    • Use the + button to add another parameter.
    • Use the trash icon to delete the selected parameter.

Actions Available

  • Save: Save the parameters you've defined.
  • Cancel: Close the window without saving changes.

Defining Return Type

The Return Type section allows you to define the type of value your stored procedure will return.

Return Type Interface

  • Name:

    • Specify the name for the return type. In the provided example, it's named procedure 1.
  • Type:

    • Choose the return type. This could be string, int, float, etc., depending on what the procedure returns.
    • In this example, the return type is string.
  • Value (Optional):

    • You can assign a default value for the return type if necessary.
  • Add/Delete Return Type:

    • Use the + button to add another return type.
    • Use the trash icon to delete the selected return type.

Actions Available

  • Save: Save the return type you've defined.
  • Cancel: Close the window without saving changes.

Sample Generated Code

CREATE PROCEDURE getUserData (IN user_id INT)
BEGIN
-- Fetch user details based on user_id
SELECT id, username, email, created_at
FROM users
WHERE id = user_id;
END;